<?php
namespace app\erp_meixingtiyu\controller;

use think\facade\Request;
use app\store\controller\Controller as StoreController;
use app\erp_meixingtiyu\logic\Course as CourseLogic;

class Course extends StoreController
{
    public function list()
    {
        $list = (new CourseLogic())->getList();
        return $this->renderSuccess($list);
    }

    public function add()
    {
        $params = Request::only([
            'name',
            'lessons',
            'class_hour',
            'class_size',
            'opening_date',
            'course_detail',
            'class_time',
            'employee_ids',
            'image_id',
            'price',
            'recommend',
            'status',
            'class_place',
            'sort',
        ]);

        (new CourseLogic())->addCourse($params);
        return $this->renderSuccess('添加成功');
    }

    public function edit()
    {
        $params = Request::only([
            'course_id',
            'name',
            'lessons',
            'class_hour',
            'class_size',
            'opening_date',
            'course_detail',
            'class_time',
            'employee_ids',
            'image_id',
            'price',
            'recommend',
            'status',
            'class_place',
            'sort',
        ]);

        (new CourseLogic())->editCourse($params);
        return $this->renderSuccess('编辑成功');
    }

    public function del($courseId)
    {
      (new CourseLogic())->deleteCourse($courseId);
      return $this->renderSuccess('删除成功');
    }

    public function orderList()
    {
      $list = (new CourseLogic())->getOrderList();
      return $this->renderSuccess($list);
    }

    // 根据日期范围获取课程订单
    public function orderListFilter($dateArr)
    {
        $list = (new CourseLogic())->getOrderListByDate($dateArr);
        return $this->renderSuccess($list);
    }

    // 获取指定课程的所有学员及其签到情况
    public function studentList($courseId)
    {
        $list = (new CourseLogic())->getStudentList($courseId);
        return $this->renderSuccess($list);
    }
}
